﻿using Common.Tool.DataTools;
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace Common.Communication
{
    public class NiVisaBase:Tool.LogBase
    {
        //--------------------------------------------------------------------------------
        // Adapted from visa32.bas which was distributed by VXIplug&play Systems Alliance
        // Distributed By Agilent Technologies, Inc.
        //--------------------------------------------------------------------------------
        // Title   : visa32.cs
        // Date    : 08-04-2010
        // Purpose : VISA definitions for C#
        //-------------------------------------------------------------------------
        private const int VI_SPEC_VERSION = 5242880;
        #region - Resource Template Functions and Operations ----------------------------
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#141", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        public static extern int viOpenDefaultRM(out int sesn);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#128", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viGetDefaultRM(out int sesn);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#129", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viFindRsrc(int sesn, string expr, out int vi, out int retCount, StringBuilder desc);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#130", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viFindNext(int vi, StringBuilder desc);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#146", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viParseRsrc(int sesn, string desc, ref short intfType, ref short intfNum);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#147", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viParseRsrcEx(int sesn, string desc, ref short intfType, ref short intfNum, StringBuilder rsrcClass, StringBuilder expandedUnaliasedName, StringBuilder aliasIfExists);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#131", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        public static extern int viOpen(int sesn, string viDesc, int mode, int timeout, out int vi);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#132", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        public static extern int viClose(int vi);

        #region viGetAttribute Overloads
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#133", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viGetAttribute(int vi, int attrName, out byte attrValue);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#133", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viGetAttribute(int vi, int attrName, out short attrValue);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#133", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viGetAttribute(int vi, int attrName, out int attrValue);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#133", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viGetAttribute(int vi, int attrName, StringBuilder attrValue);
        #endregion

        #region viSetAttribute Overloads
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#134", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viSetAttribute(int vi, int attrName, byte attrValue);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#134", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viSetAttribute(int vi, int attrName, short attrValue);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#134", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viSetAttribute(int vi, int attrName, int attrValue);
        #endregion

        [DllImportAttribute("VISA32.DLL", EntryPoint = "#142", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viStatusDesc(int vi, int status, StringBuilder desc);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#143", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viTerminate(int vi, short degree, int jobId);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#144", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viLock(int vi, int lockType, int timeout, string requestedKey, StringBuilder accessKey);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#145", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viUnlock(int vi);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#135", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viEnableEvent(int vi, int eventType, short mechanism, int context);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#136", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viDisableEvent(int vi, int eventType, short mechanism);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#137", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viDiscardEvents(int vi, int eventType, short mechanism);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#138", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viWaitOnEvent(int vi, int inEventType, int timeout, ref int outEventType, ref int outEventContext);

        private delegate int viEventHandler(int vi, int eventType, int context, int userHandle);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#139", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viInstallHandler(int vi, int eventType, viEventHandler handler, int UserHandle);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#140", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viUninstallHandler(int vi, int eventType, viEventHandler handler, int userHandle);
        #endregion

        #region - Basic I/O Operations --------------------------------------------------
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#256", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        public static extern int viRead(int vi, byte[] buffer, int count, out int retCount);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#277", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viReadAsync(int vi, byte[] buffer, int count, out int jobId);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#219", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viReadToFile(int vi, string filename, int count, ref int retCount);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#257", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viWrite(int vi, byte[] buffer, int count, out int retCount);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#278", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viWriteAsync(int vi, byte[] buffer, int count, out int jobId);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#218", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viWriteFromFile(int vi, string filename, int count, ref int retCount);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#258", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viAssertTrigger(int vi, short protocol);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#259", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viReadSTB(int vi, ref short status);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#260", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viClear(int vi);
        #endregion

        #region - Formatted and Buffered I/O Operations ---------------------------------
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#267", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viSetBuf(int vi, short mask, int bufSize);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#268", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viFlush(int vi, short mask);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#202", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viBufWrite(int vi, byte[] buffer, int count, out int retCount);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#203", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viBufRead(int vi, byte[] buffer, int count, out int retCount);

        #region viPrintf Overloads
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#269", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        public static extern int viPrintf(int vi, string writeFmt);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#269", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viPrintf(int vi, string writeFmt, int[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#269", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viPrintf(int vi, string writeFmt, short[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#269", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viPrintf(int vi, string writeFmt, float[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#269", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viPrintf(int vi, string writeFmt, double[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#269", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viPrintf(int vi, string writeFmt, byte[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#269", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viPrintf(int vi, string writeFmt, string arg);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#269", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viPrintf(int vi, string writeFmt, int arg);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#269", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viPrintf(int vi, string writeFmt, short arg);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#269", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viPrintf(int vi, string writeFmt, float arg);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#269", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viPrintf(int vi, string writeFmt, double arg);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#269", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viPrintf(int vi, string writeFmt, byte arg);
        #endregion

        #region viSPrintf Overloads
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#204", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSPrintf(int vi, StringBuilder buffer, string writeFmt);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#204", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSPrintf(int vi, StringBuilder buffer, string writeFmt, int[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#204", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSPrintf(int vi, StringBuilder buffer, string writeFmt, short[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#204", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSPrintf(int vi, StringBuilder buffer, string writeFmt, float[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#204", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSPrintf(int vi, StringBuilder buffer, string writeFmt, double[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#204", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSPrintf(int vi, StringBuilder buffer, string writeFmt, byte[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#204", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSPrintf(int vi, StringBuilder buffer, string writeFmt, string arg);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#204", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSPrintf(int vi, StringBuilder buffer, string writeFmt, int arg);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#204", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSPrintf(int vi, StringBuilder buffer, string writeFmt, short arg);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#204", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSPrintf(int vi, StringBuilder buffer, string writeFmt, float arg);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#204", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSPrintf(int vi, StringBuilder buffer, string writeFmt, double arg);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#204", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSPrintf(int vi, StringBuilder buffer, string writeFmt, byte arg);
        #endregion

        #region viScanf Overloads
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#271", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viScanf(int vi, string readFmt);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#271", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viScanf(int vi, string readFmt, int[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#271", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viScanf(int vi, string readFmt, short[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#271", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viScanf(int vi, string readFmt, float[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#271", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viScanf(int vi, string readFmt, double[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#271", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viScanf(int vi, string readFmt, byte[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#271", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viScanf(int vi, string readFmt, ref int count, int[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#271", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viScanf(int vi, string readFmt, ref int count, short[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#271", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viScanf(int vi, string readFmt, ref int count, float[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#271", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viScanf(int vi, string readFmt, ref int count, double[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#271", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viScanf(int vi, string readFmt, ref int count, byte[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#271", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viScanf(int vi, string readFmt, StringBuilder arg);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#271", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viScanf(int vi, string readFmt, ref int stringSize, StringBuilder arg);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#271", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viScanf(int vi, string readFmt, out int arg);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#271", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viScanf(int vi, string readFmt, out short arg);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#271", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viScanf(int vi, string readFmt, out float arg);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#271", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viScanf(int vi, string readFmt, out double arg);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#271", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viScanf(int vi, string readFmt, out byte arg);
        #endregion

        #region viSScanf Overloads
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#206", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSScanf(int vi, string buffer, string readFmt);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#206", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSScanf(int vi, string buffer, string readFmt, int[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#206", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSScanf(int vi, string buffer, string readFmt, short[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#206", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSScanf(int vi, string buffer, string readFmt, float[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#206", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSScanf(int vi, string buffer, string readFmt, double[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#206", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSScanf(int vi, string buffer, string readFmt, byte[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#206", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSScanf(int vi, string buffer, string readFmt, ref int count, int[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#206", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSScanf(int vi, string buffer, string readFmt, ref int count, short[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#206", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSScanf(int vi, string buffer, string readFmt, ref int count, float[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#206", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSScanf(int vi, string buffer, string readFmt, ref int count, double[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#206", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSScanf(int vi, string buffer, string readFmt, ref int count, byte[] arr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#206", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSScanf(int vi, string buffer, string readFmt, StringBuilder arg);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#206", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSScanf(int vi, string buffer, string readFmt, ref int stringSize, StringBuilder arg);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#206", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSScanf(int vi, string buffer, string readFmt, out int arg);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#206", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSScanf(int vi, string buffer, string readFmt, out short arg);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#206", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSScanf(int vi, string buffer, string readFmt, out float arg);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#206", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSScanf(int vi, string buffer, string readFmt, out double arg);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#206", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
        private static extern int viSScanf(int vi, string buffer, string readFmt, out byte arg);
        #endregion

        #endregion

        #region - Memory I/O Operations -------------------------------------------------
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#273", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viIn8(int vi, short accSpace, int offset, out byte val8);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#274", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viOut8(int vi, short accSpace, int offset, byte val8);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#261", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viIn16(int vi, short accSpace, int offset, out short val16);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#262", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viOut16(int vi, short accSpace, int offset, short val16);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#281", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viIn32(int vi, short accSpace, int offset, out int val32);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#282", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viOut32(int vi, short accSpace, int offset, int val32);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#283", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMoveIn8(int vi, short accSpace, int offset, int length, byte[] buf8);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#284", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMoveOut8(int vi, short accSpace, int offset, int length, byte[] buf8);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#285", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMoveIn16(int vi, short accSpace, int offset, int length, short[] buf16);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#286", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMoveOut16(int vi, short accSpace, int offset, int length, short[] buf16);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#287", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMoveIn32(int vi, short accSpace, int offset, int length, int[] buf32);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#288", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMoveOut32(int vi, short accSpace, int offset, int length, int[] buf32);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#200", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMove(int vi, short srcSpace, int srcOffset, short srcWidth, short destSpace, int destOffset, short destWidth, int srcLength);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#201", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMoveAsync(int vi, short srcSpace, int srcOffset, short srcWidth, short destSpace, int destOffset, short destWidth, int srcLength, out int jobId);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#263", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMapAddress(int vi, short mapSpace, int mapOffset, int mapSize, short accMode, int suggested, out int address);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#264", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viUnmapAddress(int vi);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#275", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern void viPeek8(int vi, int address, out byte val8);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#276", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern void viPoke8(int vi, int address, byte val8);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#265", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern void viPeek16(int vi, int address, out short val16);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#266", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern void viPoke16(int vi, int address, short val16);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#289", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern void viPeek32(int vi, int address, out int val32);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#290", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern void viPoke32(int vi, int address, int val32);

        #region 64-bit Extension Functions
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#220", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viIn64(int vi, short accSpace, int offset, out long val64);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#221", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viOut64(int vi, short accSpace, int offset, long val64);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#222", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viIn8Ex(int vi, short accSpace, long offset, out byte val8);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#223", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viOut8Ex(int vi, short accSpace, long offset, byte val8);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#224", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viIn16Ex(int vi, short accSpace, long offset, out short val16);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#225", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viOut16Ex(int vi, short accSpace, long offset, short val16);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#226", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viIn32Ex(int vi, short accSpace, long offset, out int val32);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#227", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viOut32Ex(int vi, short accSpace, long offset, int val32);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#228", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viIn64Ex(int vi, short accSpace, long offset, out long val64);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#229", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viOut64Ex(int vi, short accSpace, long offset, long val64);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#230", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMoveIn64(int vi, short accSpace, int offset, int length, long[] buf64);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#231", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMoveOut64(int vi, short accSpace, int offset, int length, long[] buf64);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#232", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMoveIn8Ex(int vi, short accSpace, long offset, int length, byte[] buf8);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#233", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMoveOut8Ex(int vi, short accSpace, long offset, int length, byte[] buf8);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#234", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMoveIn16Ex(int vi, short accSpace, long offset, int length, short[] buf16);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#235", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMoveOut16Ex(int vi, short accSpace, long offset, int length, short[] buf16);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#236", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMoveIn32Ex(int vi, short accSpace, long offset, int length, int[] buf32);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#237", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMoveOut32Ex(int vi, short accSpace, long offset, int length, int[] buf32);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#238", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMoveIn64Ex(int vi, short accSpace, long offset, int length, long[] buf64);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#239", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMoveOut64Ex(int vi, short accSpace, long offset, int length, long[] buf64);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#240", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMoveEx(int vi, short srcSpace, long srcOffset, short srcWidth, short destSpace, long destOffset, short destWidth, int srcLength);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#241", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMoveAsyncEx(int vi, short srcSpace, long srcOffset, short srcWidth, short destSpace, long destOffset, short destWidth, int srcLength, out int jobId);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#242", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMapAddressEx(int vi, short mapSpace, long mapOffset, int mapSize, short accMode, int suggested, out int address);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#243", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMemAllocEx(int vi, int memSize, out long offset);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#244", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMemFreeEx(int vi, long offset);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#245", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern void viPeek64(int vi, int address, out long val64);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#246", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern void viPoke64(int vi, int address, long val64);
        #endregion
        #endregion

        #region - Shared Memory Operations ----------------------------------------------
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#291", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMemAlloc(int vi, int memSize, out int offset);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#292", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMemFree(int vi, int offset);
        #endregion

        #region - Interface Specific Operations -----------------------------------------
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#208", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viGpibControlREN(int vi, short mode);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#210", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viGpibControlATN(int vi, short mode);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#211", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viGpibSendIFC(int vi);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#212", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viGpibCommand(int vi, string buffer, int count, out int retCount);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#213", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viGpibPassControl(int vi, short primAddr, short secAddr);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#209", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viVxiCommandQuery(int vi, short mode, int devCmd, out int devResponse);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#214", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viAssertUtilSignal(int vi, short line);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#215", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viAssertIntrSignal(int vi, short mode, int statusID);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#216", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viMapTrigger(int vi, short trigSrc, short trigDest, short mode);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#217", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viUnmapTrigger(int vi, short trigSrc, short trigDest);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#293", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viUsbControlOut(int vi, short bmRequestType, short bRequest, short wValue, short wIndex, short wLength, byte[] buf);
        [DllImportAttribute("VISA32.DLL", EntryPoint = "#294", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int viUsbControlIn(int vi, short bmRequestType, short bRequest, short wValue, short wIndex, short wLength, byte[] buf, out short retCnt);
        #endregion

        #region - Constants -------------------------------------------------------------

        #region - Attributes ------------------------------------------------------------
        private const int VI_ATTR_RSRC_CLASS = -1073807359;
        private const int VI_ATTR_RSRC_NAME = -1073807358;
        private const int VI_ATTR_RSRC_IMPL_VERSION = 1073676291;
        private const int VI_ATTR_RSRC_LOCK_STATE = 1073676292;
        private const int VI_ATTR_MAX_QUEUE_LENGTH = 1073676293;
        private const int VI_ATTR_USER_DATA = 1073676295;
        private const int VI_ATTR_USER_DATA_32 = 1073676295;
        private const int VI_ATTR_USER_DATA_64 = 1073676298;
        private const int VI_ATTR_FDC_CHNL = 1073676301;
        private const int VI_ATTR_FDC_MODE = 1073676303;
        private const int VI_ATTR_FDC_GEN_SIGNAL_EN = 1073676305;
        private const int VI_ATTR_FDC_USE_PAIR = 1073676307;
        private const int VI_ATTR_SEND_END_EN = 1073676310;
        private const int VI_ATTR_TERMCHAR = 1073676312;
        private const int VI_ATTR_TMO_VALUE = 1073676314;
        private const int VI_ATTR_GPIB_READDR_EN = 1073676315;
        private const int VI_ATTR_IO_PROT = 1073676316;
        private const int VI_ATTR_DMA_ALLOW_EN = 1073676318;
        private const int VI_ATTR_ASRL_BAUD = 1073676321;
        private const int VI_ATTR_ASRL_DATA_BITS = 1073676322;
        private const int VI_ATTR_ASRL_PARITY = 1073676323;
        private const int VI_ATTR_ASRL_STOP_BITS = 1073676324;
        private const int VI_ATTR_ASRL_FLOW_CNTRL = 1073676325;
        private const int VI_ATTR_RD_BUF_OPER_MODE = 1073676330;
        private const int VI_ATTR_RD_BUF_SIZE = 1073676331;
        private const int VI_ATTR_WR_BUF_OPER_MODE = 1073676333;
        private const int VI_ATTR_WR_BUF_SIZE = 1073676334;
        private const int VI_ATTR_SUPPRESS_END_EN = 1073676342;
        private const int VI_ATTR_TERMCHAR_EN = 1073676344;
        private const int VI_ATTR_DEST_ACCESS_PRIV = 1073676345;
        private const int VI_ATTR_DEST_BYTE_ORDER = 1073676346;
        private const int VI_ATTR_SRC_ACCESS_PRIV = 1073676348;
        private const int VI_ATTR_SRC_BYTE_ORDER = 1073676349;
        private const int VI_ATTR_SRC_INCREMENT = 1073676352;
        private const int VI_ATTR_DEST_INCREMENT = 1073676353;
        private const int VI_ATTR_WIN_ACCESS_PRIV = 1073676357;
        private const int VI_ATTR_WIN_BYTE_ORDER = 1073676359;
        private const int VI_ATTR_GPIB_ATN_STATE = 1073676375;
        private const int VI_ATTR_GPIB_ADDR_STATE = 1073676380;
        private const int VI_ATTR_GPIB_CIC_STATE = 1073676382;
        private const int VI_ATTR_GPIB_NDAC_STATE = 1073676386;
        private const int VI_ATTR_GPIB_SRQ_STATE = 1073676391;
        private const int VI_ATTR_GPIB_SYS_CNTRL_STATE = 1073676392;
        private const int VI_ATTR_GPIB_HS488_CBL_LEN = 1073676393;
        private const int VI_ATTR_CMDR_LA = 1073676395;
        private const int VI_ATTR_VXI_DEV_CLASS = 1073676396;
        private const int VI_ATTR_MAINFRAME_LA = 1073676400;
        private const int VI_ATTR_MANF_NAME = -1073807246;
        private const int VI_ATTR_MODEL_NAME = -1073807241;
        private const int VI_ATTR_VXI_VME_INTR_STATUS = 1073676427;
        private const int VI_ATTR_VXI_TRIG_STATUS = 1073676429;
        private const int VI_ATTR_VXI_VME_SYSFAIL_STATE = 1073676436;
        private const int VI_ATTR_WIN_BASE_ADDR = 1073676440;
        private const int VI_ATTR_WIN_BASE_ADDR_32 = 1073676440;
        private const int VI_ATTR_WIN_BASE_ADDR_64 = 1073676443;
        private const int VI_ATTR_WIN_SIZE = 1073676442;
        private const int VI_ATTR_WIN_SIZE_32 = 1073676442;
        private const int VI_ATTR_WIN_SIZE_64 = 1073676444;
        private const int VI_ATTR_ASRL_AVAIL_NUM = 1073676460;
        private const int VI_ATTR_MEM_BASE = 1073676461;
        private const int VI_ATTR_MEM_BASE_32 = 1073676461;
        private const int VI_ATTR_MEM_BASE_64 = 1073676496;
        private const int VI_ATTR_ASRL_CTS_STATE = 1073676462;
        private const int VI_ATTR_ASRL_DCD_STATE = 1073676463;
        private const int VI_ATTR_ASRL_DSR_STATE = 1073676465;
        private const int VI_ATTR_ASRL_DTR_STATE = 1073676466;
        private const int VI_ATTR_ASRL_END_IN = 1073676467;
        private const int VI_ATTR_ASRL_END_OUT = 1073676468;
        private const int VI_ATTR_ASRL_REPLACE_CHAR = 1073676478;
        private const int VI_ATTR_ASRL_RI_STATE = 1073676479;
        private const int VI_ATTR_ASRL_RTS_STATE = 1073676480;
        private const int VI_ATTR_ASRL_XON_CHAR = 1073676481;
        private const int VI_ATTR_ASRL_XOFF_CHAR = 1073676482;
        private const int VI_ATTR_WIN_ACCESS = 1073676483;
        private const int VI_ATTR_RM_SESSION = 1073676484;
        private const int VI_ATTR_VXI_LA = 1073676501;
        private const int VI_ATTR_MANF_ID = 1073676505;
        private const int VI_ATTR_MEM_SIZE = 1073676509;
        private const int VI_ATTR_MEM_SIZE_32 = 1073676509;
        private const int VI_ATTR_MEM_SIZE_64 = 1073676497;
        private const int VI_ATTR_MEM_SPACE = 1073676510;
        private const int VI_ATTR_MODEL_CODE = 1073676511;
        private const int VI_ATTR_SLOT = 1073676520;
        private const int VI_ATTR_INTF_INST_NAME = -1073807127;
        private const int VI_ATTR_IMMEDIATE_SERV = 1073676544;
        private const int VI_ATTR_INTF_PARENT_NUM = 1073676545;
        private const int VI_ATTR_RSRC_SPEC_VERSION = 1073676656;
        private const int VI_ATTR_INTF_TYPE = 1073676657;
        private const int VI_ATTR_GPIB_PRIMARY_ADDR = 1073676658;
        private const int VI_ATTR_GPIB_SECONDARY_ADDR = 1073676659;
        private const int VI_ATTR_RSRC_MANF_NAME = -1073806988;
        private const int VI_ATTR_RSRC_MANF_ID = 1073676661;
        private const int VI_ATTR_INTF_NUM = 1073676662;
        private const int VI_ATTR_TRIG_ID = 1073676663;
        private const int VI_ATTR_GPIB_REN_STATE = 1073676673;
        private const int VI_ATTR_GPIB_UNADDR_EN = 1073676676;
        private const int VI_ATTR_DEV_STATUS_BYTE = 1073676681;
        private const int VI_ATTR_FILE_APPEND_EN = 1073676690;
        private const int VI_ATTR_VXI_TRIG_SUPPORT = 1073676692;
        private const int VI_ATTR_TCPIP_ADDR = -1073806955;
        private const int VI_ATTR_TCPIP_HOSTNAME = -1073806954;
        private const int VI_ATTR_TCPIP_PORT = 1073676695;
        private const int VI_ATTR_TCPIP_DEVICE_NAME = -1073806951;
        private const int VI_ATTR_TCPIP_NODELAY = 1073676698;
        private const int VI_ATTR_TCPIP_KEEPALIVE = 1073676699;
        private const int VI_ATTR_4882_COMPLIANT = 1073676703;
        private const int VI_ATTR_USB_SERIAL_NUM = -1073806944;
        private const int VI_ATTR_USB_INTFC_NUM = 1073676705;
        private const int VI_ATTR_USB_PROTOCOL = 1073676711;
        private const int VI_ATTR_USB_MAX_INTR_SIZE = 1073676719;
        private const int VI_ATTR_PXI_DEV_NUM = 1073676801;
        private const int VI_ATTR_PXI_FUNC_NUM = 1073676802;
        private const int VI_ATTR_PXI_BUS_NUM = 1073676805;
        private const int VI_ATTR_PXI_CHASSIS = 1073676806;
        private const int VI_ATTR_PXI_SLOTPATH = -1073806841;
        private const int VI_ATTR_PXI_SLOT_LBUS_LEFT = 1073676808;
        private const int VI_ATTR_PXI_SLOT_LBUS_RIGHT = 1073676809;
        private const int VI_ATTR_PXI_TRIG_BUS = 1073676810;
        private const int VI_ATTR_PXI_STAR_TRIG_BUS = 1073676811;
        private const int VI_ATTR_PXI_STAR_TRIG_LINE = 1073676812;
        private const int VI_ATTR_PXI_MEM_TYPE_BAR0 = 1073676817;
        private const int VI_ATTR_PXI_MEM_TYPE_BAR1 = 1073676818;
        private const int VI_ATTR_PXI_MEM_TYPE_BAR2 = 1073676819;
        private const int VI_ATTR_PXI_MEM_TYPE_BAR3 = 1073676820;
        private const int VI_ATTR_PXI_MEM_TYPE_BAR4 = 1073676821;
        private const int VI_ATTR_PXI_MEM_TYPE_BAR5 = 1073676822;
        private const int VI_ATTR_PXI_MEM_BASE_BAR0 = 1073676833;
        private const int VI_ATTR_PXI_MEM_BASE_BAR1 = 1073676834;
        private const int VI_ATTR_PXI_MEM_BASE_BAR2 = 1073676835;
        private const int VI_ATTR_PXI_MEM_BASE_BAR3 = 1073676836;
        private const int VI_ATTR_PXI_MEM_BASE_BAR4 = 1073676837;
        private const int VI_ATTR_PXI_MEM_BASE_BAR5 = 1073676838;
        private const int VI_ATTR_PXI_MEM_SIZE_BAR0 = 1073676849;
        private const int VI_ATTR_PXI_MEM_SIZE_BAR1 = 1073676850;
        private const int VI_ATTR_PXI_MEM_SIZE_BAR2 = 1073676851;
        private const int VI_ATTR_PXI_MEM_SIZE_BAR3 = 1073676852;
        private const int VI_ATTR_PXI_MEM_SIZE_BAR4 = 1073676853;
        private const int VI_ATTR_PXI_MEM_SIZE_BAR5 = 1073676854;
        private const int VI_ATTR_PXI_IS_EXPRESS = 1073676864;
        private const int VI_ATTR_PXI_SLOT_LWIDTH = 1073676865;
        private const int VI_ATTR_PXI_MAX_LWIDTH = 1073676866;
        private const int VI_ATTR_PXI_ACTUAL_LWIDTH = 1073676867;
        private const int VI_ATTR_PXI_DSTAR_BUS = 1073676868;
        private const int VI_ATTR_PXI_DSTAR_SET = 1073676869;
        private const int VI_ATTR_TCPIP_HISLIP_OVERLAP_EN = 1073677056;
        private const int VI_ATTR_TCPIP_HISLIP_VERSION = 1073677057;
        private const int VI_ATTR_TCPIP_HISLIP_MAX_MESSAGE_KB = 1073677058;
        private const int VI_ATTR_JOB_ID = 1073692678;
        private const int VI_ATTR_EVENT_TYPE = 1073692688;
        private const int VI_ATTR_SIGP_STATUS_ID = 1073692689;
        private const int VI_ATTR_RECV_TRIG_ID = 1073692690;
        private const int VI_ATTR_INTR_STATUS_ID = 1073692707;
        private const int VI_ATTR_STATUS = 1073692709;
        private const int VI_ATTR_RET_COUNT = 1073692710;
        private const int VI_ATTR_RET_COUNT_32 = 1073692710;
        private const int VI_ATTR_RET_COUNT_64 = 1073692712;
        private const int VI_ATTR_BUFFER = 1073692711;
        private const int VI_ATTR_RECV_INTR_LEVEL = 1073692737;
        private const int VI_ATTR_OPER_NAME = -1073790910;
        private const int VI_ATTR_GPIB_RECV_CIC_STATE = 1073693075;
        private const int VI_ATTR_RECV_TCPIP_ADDR = -1073790568;
        private const int VI_ATTR_USB_RECV_INTR_SIZE = 1073693104;
        private const int VI_ATTR_USB_RECV_INTR_DATA = -1073790543;
        #endregion

        #region - Event Types -----------------------------------------------------------
        private const int VI_EVENT_IO_COMPLETION = 1073684489;
        private const int VI_EVENT_TRIG = -1073799158;
        private const int VI_EVENT_SERVICE_REQ = 1073684491;
        private const int VI_EVENT_CLEAR = 1073684493;
        private const int VI_EVENT_EXCEPTION = -1073799154;
        private const int VI_EVENT_GPIB_CIC = 1073684498;
        private const int VI_EVENT_GPIB_TALK = 1073684499;
        private const int VI_EVENT_GPIB_LISTEN = 1073684500;
        private const int VI_EVENT_VXI_VME_SYSFAIL = 1073684509;
        private const int VI_EVENT_VXI_VME_SYSRESET = 1073684510;
        private const int VI_EVENT_VXI_SIGP = 1073684512;
        private const int VI_EVENT_VXI_VME_INTR = -1073799135;
        private const int VI_EVENT_PXI_INTR = 1073684514;
        private const int VI_EVENT_TCPIP_CONNECT = 1073684534;
        private const int VI_EVENT_USB_INTR = 1073684535;
        private const int VI_ALL_ENABLED_EVENTS = 1073709055;
        #endregion

        #region - Completion and Error Codes --------------------------------------------
        private const int VI_SUCCESS = 0;
        private const int VI_SUCCESS_EVENT_EN = 1073676290;
        private const int VI_SUCCESS_EVENT_DIS = 1073676291;
        private const int VI_SUCCESS_QUEUE_EMPTY = 1073676292;
        private const int VI_SUCCESS_TERM_CHAR = 1073676293;
        private const int VI_SUCCESS_MAX_CNT = 1073676294;
        private const int VI_SUCCESS_DEV_NPRESENT = 1073676413;
        private const int VI_SUCCESS_TRIG_MAPPED = 1073676414;
        private const int VI_SUCCESS_QUEUE_NEMPTY = 1073676416;
        private const int VI_SUCCESS_NCHAIN = 1073676440;
        private const int VI_SUCCESS_NESTED_SHARED = 1073676441;
        private const int VI_SUCCESS_NESTED_EXCLUSIVE = 1073676442;
        private const int VI_SUCCESS_SYNC = 1073676443;
        private const int VI_WARN_QUEUE_OVERFLOW = 1073676300;
        private const int VI_WARN_CONFIG_NLOADED = 1073676407;
        private const int VI_WARN_NULL_OBJECT = 1073676418;
        private const int VI_WARN_NSUP_ATTR_STATE = 1073676420;
        private const int VI_WARN_UNKNOWN_STATUS = 1073676421;
        private const int VI_WARN_NSUP_BUF = 1073676424;
        private const int VI_WARN_EXT_FUNC_NIMPL = 1073676457;
        private const int VI_ERROR_SYSTEM_ERROR = -1073807360;
        private const int VI_ERROR_INV_OBJECT = -1073807346;
        private const int VI_ERROR_RSRC_LOCKED = -1073807345;
        private const int VI_ERROR_INV_EXPR = -1073807344;
        private const int VI_ERROR_RSRC_NFOUND = -1073807343;
        private const int VI_ERROR_INV_RSRC_NAME = -1073807342;
        private const int VI_ERROR_INV_ACC_MODE = -1073807341;
        private const int VI_ERROR_TMO = -1073807339;
        private const int VI_ERROR_CLOSING_FAILED = -1073807338;
        private const int VI_ERROR_INV_DEGREE = -1073807333;
        private const int VI_ERROR_INV_JOB_ID = -1073807332;
        private const int VI_ERROR_NSUP_ATTR = -1073807331;
        private const int VI_ERROR_NSUP_ATTR_STATE = -1073807330;
        private const int VI_ERROR_ATTR_READONLY = -1073807329;
        private const int VI_ERROR_INV_LOCK_TYPE = -1073807328;
        private const int VI_ERROR_INV_ACCESS_KEY = -1073807327;
        private const int VI_ERROR_INV_EVENT = -1073807322;
        private const int VI_ERROR_INV_MECH = -1073807321;
        private const int VI_ERROR_HNDLR_NINSTALLED = -1073807320;
        private const int VI_ERROR_INV_HNDLR_REF = -1073807319;
        private const int VI_ERROR_INV_CONTEXT = -1073807318;
        private const int VI_ERROR_QUEUE_OVERFLOW = -1073807315;
        private const int VI_ERROR_NENABLED = -1073807313;
        private const int VI_ERROR_ABORT = -1073807312;
        private const int VI_ERROR_RAW_WR_PROT_VIOL = -1073807308;
        private const int VI_ERROR_RAW_RD_PROT_VIOL = -1073807307;
        private const int VI_ERROR_OUTP_PROT_VIOL = -1073807306;
        private const int VI_ERROR_INP_PROT_VIOL = -1073807305;
        private const int VI_ERROR_BERR = -1073807304;
        private const int VI_ERROR_IN_PROGRESS = -1073807303;
        private const int VI_ERROR_INV_SETUP = -1073807302;
        private const int VI_ERROR_QUEUE_ERROR = -1073807301;
        private const int VI_ERROR_ALLOC = -1073807300;
        private const int VI_ERROR_INV_MASK = -1073807299;
        private const int VI_ERROR_IO = -1073807298;
        private const int VI_ERROR_INV_FMT = -1073807297;
        private const int VI_ERROR_NSUP_FMT = -1073807295;
        private const int VI_ERROR_LINE_IN_USE = -1073807294;
        private const int VI_ERROR_NSUP_MODE = -1073807290;
        private const int VI_ERROR_SRQ_NOCCURRED = -1073807286;
        private const int VI_ERROR_INV_SPACE = -1073807282;
        private const int VI_ERROR_INV_OFFSET = -1073807279;
        private const int VI_ERROR_INV_WIDTH = -1073807278;
        private const int VI_ERROR_NSUP_OFFSET = -1073807276;
        private const int VI_ERROR_NSUP_VAR_WIDTH = -1073807275;
        private const int VI_ERROR_WINDOW_NMAPPED = -1073807273;
        private const int VI_ERROR_RESP_PENDING = -1073807271;
        private const int VI_ERROR_NLISTENERS = -1073807265;
        private const int VI_ERROR_NCIC = -1073807264;
        private const int VI_ERROR_NSYS_CNTLR = -1073807263;
        private const int VI_ERROR_NSUP_OPER = -1073807257;
        private const int VI_ERROR_INTR_PENDING = -1073807256;
        private const int VI_ERROR_ASRL_PARITY = -1073807254;
        private const int VI_ERROR_ASRL_FRAMING = -1073807253;
        private const int VI_ERROR_ASRL_OVERRUN = -1073807252;
        private const int VI_ERROR_TRIG_NMAPPED = -1073807250;
        private const int VI_ERROR_NSUP_ALIGN_OFFSET = -1073807248;
        private const int VI_ERROR_USER_BUF = -1073807247;
        private const int VI_ERROR_RSRC_BUSY = -1073807246;
        private const int VI_ERROR_NSUP_WIDTH = -1073807242;
        private const int VI_ERROR_INV_PARAMETER = -1073807240;
        private const int VI_ERROR_INV_PROT = -1073807239;
        private const int VI_ERROR_INV_SIZE = -1073807237;
        private const int VI_ERROR_WINDOW_MAPPED = -1073807232;
        private const int VI_ERROR_NIMPL_OPER = -1073807231;
        private const int VI_ERROR_INV_LENGTH = -1073807229;
        private const int VI_ERROR_INV_MODE = -1073807215;
        private const int VI_ERROR_SESN_NLOCKED = -1073807204;
        private const int VI_ERROR_MEM_NSHARED = -1073807203;
        private const int VI_ERROR_LIBRARY_NFOUND = -1073807202;
        private const int VI_ERROR_NSUP_INTR = -1073807201;
        private const int VI_ERROR_INV_LINE = -1073807200;
        private const int VI_ERROR_FILE_ACCESS = -1073807199;
        private const int VI_ERROR_FILE_IO = -1073807198;
        private const int VI_ERROR_NSUP_LINE = -1073807197;
        private const int VI_ERROR_NSUP_MECH = -1073807196;
        private const int VI_ERROR_INTF_NUM_NCONFIG = -1073807195;
        private const int VI_ERROR_CONN_LOST = -1073807194;
        private const int VI_ERROR_MACHINE_NAVAIL = -1073807193;
        private const int VI_ERROR_NPERMISSION = -1073807192;
        #endregion

        #region - Other VISA Definitions ------------------------------------------------
        private const short VI_FIND_BUFLEN = 256;

        private const short VI_NULL = 0;
        private const short VI_TRUE = 1;
        private const short VI_FALSE = 0;

        private const short VI_INTF_GPIB = 1;
        private const short VI_INTF_VXI = 2;
        private const short VI_INTF_GPIB_VXI = 3;
        private const short VI_INTF_ASRL = 4;
        private const short VI_INTF_PXI = 5;
        private const short VI_INTF_TCPIP = 6;
        private const short VI_INTF_USB = 7;

        private const short VI_PROT_NORMAL = 1;
        private const short VI_PROT_FDC = 2;
        private const short VI_PROT_HS488 = 3;
        private const short VI_PROT_4882_STRS = 4;
        private const short VI_PROT_USBTMC_VENDOR = 5;

        private const short VI_FDC_NORMAL = 1;
        private const short VI_FDC_STREAM = 2;

        private const short VI_LOCAL_SPACE = 0;
        private const short VI_A16_SPACE = 1;
        private const short VI_A24_SPACE = 2;
        private const short VI_A32_SPACE = 3;
        private const short VI_A64_SPACE = 4;
        private const short VI_PXI_ALLOC_SPACE = 9;
        private const short VI_PXI_CFG_SPACE = 10;
        private const short VI_PXI_BAR0_SPACE = 11;
        private const short VI_PXI_BAR1_SPACE = 12;
        private const short VI_PXI_BAR2_SPACE = 13;
        private const short I_PXI_BAR3_SPACE = 14;
        private const short VI_PXI_BAR4_SPACE = 15;
        private const short VI_PXI_BAR5_SPACE = 16;
        private const short VI_OPAQUE_SPACE = -1;

        private const short VI_UNKNOWN_LA = -1;
        private const short VI_UNKNOWN_SLOT = -1;
        private const short VI_UNKNOWN_LEVEL = -1;
        private const short VI_UNKNOWN_CHASSIS = -1;

        private const short VI_QUEUE = 1;
        private const short VI_HNDLR = 2;
        private const short VI_SUSPEND_HNDLR = 4;
        private const short VI_ALL_MECH = -1;
        private const short VI_ANY_HNDLR = 0;

        private const short VI_TRIG_ALL = -2;
        private const short VI_TRIG_SW = -1;
        private const short VI_TRIG_TTL0 = 0;
        private const short VI_TRIG_TTL1 = 1;
        private const short VI_TRIG_TTL2 = 2;
        private const short VI_TRIG_TTL3 = 3;
        private const short VI_TRIG_TTL4 = 4;
        private const short VI_TRIG_TTL5 = 5;
        private const short VI_TRIG_TTL6 = 6;
        private const short VI_TRIG_TTL7 = 7;
        private const short VI_TRIG_ECL0 = 8;
        private const short VI_TRIG_ECL1 = 9;
        private const short VI_TRIG_PANEL_IN = 27;
        private const short VI_TRIG_PANEL_OUT = 28;

        private const short VI_TRIG_PROT_DEFAULT = 0;
        private const short VI_TRIG_PROT_ON = 1;
        private const short VI_TRIG_PROT_OFF = 2;
        private const short VI_TRIG_PROT_SYNC = 5;
        private const short VI_TRIG_PROT_RESERVE = 6;
        private const short VI_TRIG_PROT_UNRESERVE = 7;

        private const short VI_READ_BUF = 1;
        private const short VI_WRITE_BUF = 2;
        private const short VI_READ_BUF_DISCARD = 4;
        private const short VI_WRITE_BUF_DISCARD = 8;
        private const short VI_IO_IN_BUF = 16;
        private const short VI_IO_OUT_BUF = 32;
        private const short VI_IO_IN_BUF_DISCARD = 64;
        private const short VI_IO_OUT_BUF_DISCARD = 128;

        private const short VI_FLUSH_ON_ACCESS = 1;
        private const short VI_FLUSH_WHEN_FULL = 2;
        private const short VI_FLUSH_DISABLE = 3;

        private const short VI_NMAPPED = 1;
        private const short VI_USE_OPERS = 2;
        private const short VI_DEREF_ADDR = 3;
        private const short VI_DEREF_ADDR_BYTE_SWAP = 4;

        private const int VI_TMO_IMMEDIATE = 0;
        private const int VI_TMO_INFINITE = -1;

        private const short VI_NO_LOCK = 0;
        private const short VI_EXCLUSIVE_LOCK = 1;
        private const short VI_SHARED_LOCK = 2;
        private const short VI_LOAD_CONFIG = 4;

        private const short VI_NO_SEC_ADDR = -1;

        private const short VI_ASRL_PAR_NONE = 0;
        private const short VI_ASRL_PAR_ODD = 1;
        private const short VI_ASRL_PAR_EVEN = 2;
        private const short VI_ASRL_PAR_MARK = 3;
        private const short VI_ASRL_PAR_SPACE = 4;

        private const short VI_ASRL_STOP_ONE = 10;
        private const short VI_ASRL_STOP_ONE5 = 15;
        private const short VI_ASRL_STOP_TWO = 20;

        private const short VI_ASRL_FLOW_NONE = 0;
        private const short VI_ASRL_FLOW_XON_XOFF = 1;
        private const short VI_ASRL_FLOW_RTS_CTS = 2;
        private const short VI_ASRL_FLOW_DTR_DSR = 4;

        private const short VI_ASRL_END_NONE = 0;
        private const short VI_ASRL_END_LAST_BIT = 1;
        private const short VI_ASRL_END_TERMCHAR = 2;
        private const short VI_ASRL_END_BREAK = 3;

        private const short VI_STATE_ASSERTED = 1;
        private const short VI_STATE_UNASSERTED = 0;
        private const short VI_STATE_UNKNOWN = -1;

        private const short VI_BIG_ENDIAN = 0;
        private const short VI_LITTLE_ENDIAN = 1;

        private const short VI_DATA_PRIV = 0;
        private const short VI_DATA_NPRIV = 1;
        private const short VI_PROG_PRIV = 2;
        private const short VI_PROG_NPRIV = 3;
        private const short VI_BLCK_PRIV = 4;
        private const short VI_BLCK_NPRIV = 5;
        private const short VI_D64_PRIV = 6;
        private const short VI_D64_NPRIV = 7;

        private const short VI_WIDTH_8 = 1;
        private const short VI_WIDTH_16 = 2;
        private const short VI_WIDTH_32 = 4;
        private const short VI_WIDTH_64 = 8;

        private const short VI_GPIB_REN_DEASSERT = 0;
        private const short VI_GPIB_REN_ASSERT = 1;
        private const short VI_GPIB_REN_DEASSERT_GTL = 2;
        private const short VI_GPIB_REN_ASSERT_ADDRESS = 3;
        private const short VI_GPIB_REN_ASSERT_LLO = 4;
        private const short VI_GPIB_REN_ASSERT_ADDRESS_LLO = 5;
        private const short VI_GPIB_REN_ADDRESS_GTL = 6;

        private const short VI_GPIB_ATN_DEASSERT = 0;
        private const short VI_GPIB_ATN_ASSERT = 1;
        private const short VI_GPIB_ATN_DEASSERT_HANDSHAKE = 2;
        private const short VI_GPIB_ATN_ASSERT_IMMEDIATE = 3;

        private const short VI_GPIB_HS488_DISABLED = 0;
        private const short VI_GPIB_HS488_NIMPL = -1;

        private const short VI_GPIB_UNADDRESSED = 0;
        private const short VI_GPIB_TALKER = 1;
        private const short VI_GPIB_LISTENER = 2;

        private const short VI_VXI_CMD16 = 512;
        private const short VI_VXI_CMD16_RESP16 = 514;
        private const short VI_VXI_RESP16 = 2;
        private const short VI_VXI_CMD32 = 1024;
        private const short VI_VXI_CMD32_RESP16 = 1026;
        private const short VI_VXI_CMD32_RESP32 = 1028;
        private const short VI_VXI_RESP32 = 4;

        private const short VI_ASSERT_SIGNAL = -1;
        private const short VI_ASSERT_USE_ASSIGNED = 0;
        private const short VI_ASSERT_IRQ1 = 1;
        private const short VI_ASSERT_IRQ2 = 2;
        private const short VI_ASSERT_IRQ3 = 3;
        private const short VI_ASSERT_IRQ4 = 4;
        private const short VI_ASSERT_IRQ5 = 5;
        private const short VI_ASSERT_IRQ6 = 6;
        private const short VI_ASSERT_IRQ7 = 7;

        private const short VI_UTIL_ASSERT_SYSRESET = 1;
        private const short VI_UTIL_ASSERT_SYSFAIL = 2;
        private const short VI_UTIL_DEASSERT_SYSFAIL = 3;

        private const short VI_VXI_CLASS_MEMORY = 0;
        private const short VI_VXI_CLASS_EXTENDED = 1;
        private const short VI_VXI_CLASS_MESSAGE = 2;
        private const short VI_VXI_CLASS_REGISTER = 3;
        private const short VI_VXI_CLASS_OTHER = 4;
        private const short VI_PXI_ADDR_NONE = 0;
        private const short VI_PXI_ADDR_MEM = 1;
        private const short VI_PXI_ADDR_IO = 2;
        private const short VI_PXI_ADDR_CFG = 3;

        private const short VI_TRIG_UNKNOWN = -1;
        private const short VI_PXI_LBUS_UNKNOWN = -1;
        private const short VI_PXI_LBUS_NONE = 0;
        private const short VI_PXI_LBUS_STAR_TRIG_BUS_0 = 1000;
        private const short VI_PXI_LBUS_STAR_TRIG_BUS_1 = 1001;
        private const short VI_PXI_LBUS_STAR_TRIG_BUS_2 = 1002;
        private const short VI_PXI_LBUS_STAR_TRIG_BUS_3 = 1003;
        private const short VI_PXI_LBUS_STAR_TRIG_BUS_4 = 1004;
        private const short VI_PXI_LBUS_STAR_TRIG_BUS_5 = 1005;
        private const short VI_PXI_LBUS_STAR_TRIG_BUS_6 = 1006;
        private const short VI_PXI_LBUS_STAR_TRIG_BUS_7 = 1007;
        private const short VI_PXI_LBUS_STAR_TRIG_BUS_8 = 1008;
        private const short VI_PXI_LBUS_STAR_TRIG_BUS_9 = 1009;
        private const short VI_PXI_STAR_TRIG_CONTROLLER = 1413;

        #endregion

        #region - Backward Compatibility Macros -----------------------------------------
        private const int VI_ERROR_INV_SESSION = -1073807346;
        private const int VI_INFINITE = -1;
        private const short VI_NORMAL = 1;
        private const short VI_FDC = 2;
        private const short VI_HS488 = 3;
        private const short VI_ASRL488 = 4;
        private const short VI_ASRL_IN_BUF = 16;
        private const short VI_ASRL_OUT_BUF = 32;
        private const short VI_ASRL_IN_BUF_DISCARD = 64;
        private const short VI_ASRL_OUT_BUF_DISCARD = 128;
        #endregion

        #endregion

        protected int viDefRm;
        protected int viSession;
        protected int timeout;
        public bool IsConnected => viSession != 0;
        /// <summary>
        /// 序列号
        /// </summary>
        protected string sn { get; set; }
        /// <summary>
        /// 设置序列号
        /// </summary>
        public NiVisaBase(string sn,int timeout = 1500)
        {
            this.sn = sn;
            this.timeout = timeout;
        }
        /// <summary>
        /// 连接
        /// </summary> 
        /// <returns></returns>
        public Result Open()
        {
            var result = new Result();
            try
            {
                AppendCommunication(sn, "打开连接");
                viOpenDefaultRM(out viDefRm);
                viOpen(viDefRm, sn, 0, timeout, out viSession);
                result.IsSucceed = viSession != 0;
            }
            catch (Exception ex)
            {
                AppendErr(sn, "打开连接失败", ex);
                result.IsSucceed = false;
                result.Err = ex.Message;
                result.ErrCode = 408;
                result.Exception = ex;
            }
            return result.EndTime();
        }

        /// <summary>
        /// 关闭连接
        /// </summary>
        /// <returns></returns>
        public Result Close()
        {
            var result = new Result();
            try
            {
                AppendCommunication(sn, "关闭连接");
                viClose(viSession);
                viClose(viDefRm);
                viSession = 0;
            }
            catch (Exception ex)
            {
                AppendErr(sn, "关闭连接失败", ex);
                result.IsSucceed = false;
                result.Err = ex.Message;
            }
            return result.EndTime();
        }

        /// <summary>
        /// 发送
        /// </summary>
        /// <returns></returns>
        protected virtual Result Write(string command)
        {
            var result = new Result();
            try
            {
                result.Requst = command;
                AppendCommunication(sn, "->" + result.Requst);
                //发送命令
                //0为成功
                result.IsSucceed = viPrintf(viSession, command) == 0;
                return result.EndTime();
            }
            catch (Exception ex)
            {
                AppendErr(sn, "发送失败", ex);
                result.IsSucceed = false;
                result.Err = ex.Message;
            }
            return result.EndTime();
        }
        /// <summary>
        /// 读取
        /// </summary>
        /// <returns></returns>
        protected virtual Result<string> ReadString()
        {
            Result<string> result = new Result<string>();
            try
            {
                //发送命令
                int retCnt;
                string strIdn = string.Empty;
                byte[] byteReadBuf = new byte[128]; ;
                //0为成功
                result.IsSucceed = viRead(viSession, byteReadBuf, 128, out retCnt) == 0;
                if (retCnt == 0)
                {
                    result.IsSucceed = false;
                    result.Err = "返回超时";
                    AppendCommunication(sn, result.Err);
                    return result.EndTime();
                }
                //解析返回值
                for (int i = 0; i < retCnt; i++)
                {
                    strIdn = strIdn + Convert.ToChar(byteReadBuf[i]);
                }
                result.Value = strIdn;
                result.Response = strIdn;
                AppendCommunication(sn, "<-" + result.Response);
                return result.EndTime();
            }
            catch (Exception ex)
            {
                AppendErr(sn, "读取返回失败", ex);
                result.IsSucceed = false;
                result.Err = ex.Message;
            }
            return result.EndTime();
        }

        /// <summary>
        /// 发送报文，并获取响应报文
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        protected virtual Result<string> WriteThenRead(string command, int wait = 100, bool tryagain = true)
        {
            Result<string> result = new Result<string>();
            Result<string> _writeThenRead()
            {
                try
                {
                    //发送命令
                    var re = Write(command);
                    if (!re.IsSucceed)
                    {
                        return new Result<string>(re, result.InitialTime);
                    }
                    Thread.Sleep(wait);
                    var re2 = ReadString();
                    re2.Requst = re.Requst;
                    //获取响应报文
                    return new Result<string>(re2, result.InitialTime);
                }
                catch (Exception ex)
                {
                    result.IsSucceed = false;
                    result.Err = ex.Message;
                    result.AddErr2List();
                    return result.EndTime();
                }
            }
            //从发送命令到读取响应为最小单元，避免多线程执行串数据（可线程安全执行）
            lock (this)
            {
                result = _writeThenRead();
                if (!result.IsSucceed && tryagain)
                {
                    Thread.Sleep(100);
                    result = _writeThenRead();
                }
                return result;
            }
        }
    }
}
